package nku.csc360;

import java.util.Date;

public class Saving extends Account{

	//Used to set amount of bankwithdrawals
	public final static int bankwithdrawals = 10;

	//Used to mantain running amount of withdrawals
	public int withdrawals = bankwithdrawals; 
	
	//Setting Default Constructor	
    public Saving() {
    	super();
    }
    
    //Constructor to initilize values
    public Saving(int id, double balance, double annualInterestRate, Date dateCreated){
    	//Calling super constructor to set default values
    	super(id, balance, annualInterestRate, dateCreated);			
    }
    
    //Method to get the amount of withdrawals....
    public int getWithdrawals(){
    	return this.withdrawals;
    }
    
    public void withdraw(double amount){
    		
    	if((getBalance()-amount) > 0){
 
    		//If no more withdrawals can take place...
    		if (this.withdrawals == 0){
    		
    			//Display an error when you have reached allocted amount of withdrawals in a month
    			System.out.println("-> Withdraw operation cannot be completed: max number of withdrawals exceeded.");
    			return;
    		}
    	
    		//If there are still more withdrawals 
    		else if (this.withdrawals > 0){
    			//Deducting no. of withdrawals allowed
    			withdrawals--;
    		
    			//Deduct amount withdrawn from balance
    			setBalance(getBalance() - amount);
    		}
    	
    		//There has been a negative amount of withdrawals
    		else
    			System.out.println("There has been an error in the Withdraw Method");
    			
    		System.out.println("Withdrawn : " + amount + " from savings account " + getId() + ", Balance: " + getBalance());
    	}
    	else
    		System.out.println("Withdraw operation cannot be completed: no cash available.");
    }
    
    //Overiding deposit method so the implementation suits what needs to be done for a deposit in a savings account
    public void deposit(double amount) {
    	setBalance(getBalance() + amount);
    	System.out.println("Deposited : " + amount + " from savings account " + getId() + ", Balance: " + getBalance());
  	}
    
    public String toString() {
    	return "Account " + getId() + " (created " + getDateCreated() + ") has balance " + getBalance() +" and no. withdrawals per month " + bankwithdrawals;
  	}
}
